import { Body, Controller, Get, HttpException, HttpStatus, Patch } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { ButtonService } from './button.service'
import { UpdateButtonDto } from './dto/button.dto'

@ApiTags('后台/按钮配置')
@Controller('admin/button')
export class ButtonController {
  constructor(private readonly buttonService: ButtonService) {}

  /**
   * 获取按钮配置
   */
  @Get()
  detail() {
    return this.buttonService.findOne({})
  }

  /**
   * 更新按钮配置
   */
  @Patch()
  async update(@Body() data: UpdateButtonDto) {
    const findData = await this.buttonService.findOne({})
    if (!findData) {
      throw new HttpException('按钮配置不存在', HttpStatus.NOT_FOUND)
    }

    this.buttonService.update(findData.buttonId, data)
  }
}

@ApiTags('官网/按钮配置')
@Controller('web/button')
export class WebButtonController {
  constructor(private readonly buttonService: ButtonService) {}

  /**
   * 获取按钮配置
   */
  @Get()
  webDetail() {
    return this.buttonService.findOne({})
  }
}
